package com.woniuxy.microsysserver.service.impl;

import com.woniuxy.microsysserver.bean.AdminInfo;
import com.woniuxy.microsysserver.mapper.AdminMapper;
import com.woniuxy.microsysserver.service.IAdminService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional(readOnly = true)
@Service
public class AdminServiceImpl implements IAdminService {
    @Resource
    private AdminMapper adminMapper;
    @Override
    public AdminInfo login(String loginName) {
        return adminMapper.login(loginName);
    }


    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @Override
    public void saveAdminInfo(AdminInfo adminInfo) {
        adminMapper.saveAdminInfo(adminInfo);
    }

    @Override
    public List<AdminInfo> findAll() {
        return adminMapper.findAll();
    }

    @Override
    public List<AdminInfo> findByCondition(AdminInfo adminInfo) {
        return adminMapper.findByCondition(adminInfo);
    }

    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @Override
    public void delete(Integer id) {
        adminMapper.delete(id);
    }

    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @Override
    public void update(AdminInfo adminInfo) {
        System.out.println(adminInfo);
        adminMapper.updateAdmin(adminInfo);
    }

    @Override
    public List<AdminInfo> findByRole(Integer rid) {
        return adminMapper.findByRole(rid);
    }

    @Override
    public AdminInfo findById(Integer id) {
        return adminMapper.findById(id);
    }
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @Override
    public void changeHead(AdminInfo adminInfo) {
        adminMapper.changeHead(adminInfo);
    }
}
